package com.lottery.im.module.service.ui;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.fondesa.recyclerviewdivider.RecyclerViewDivider;
import com.lottery.im.R;
import com.lottery.im.api.result.entity.bank.BankList;
import com.lottery.im.base.BaseSwipeFragment;
import com.lottery.im.module.service.adapter.BankListAdapter;
import com.lottery.im.module.service.presenter.AddBankPresenter;
import com.lottery.im.module.service.view.AddBankView;
import java.util.List;

/**
 * 作者：cyy
 * 时间：2018/9/26。
 */
public class AddBankFragment extends BaseSwipeFragment<AddBankPresenter> implements AddBankView {
  @BindView(R.id.tv_title) TextView tvTitle;
  @BindView(R.id.recycleView) RecyclerView recycleView;
  private BankListAdapter mAdapter;

  public final static int RESULTCODE=200;

  @Override protected int getLayoutResId() {
    return R.layout.bank_detail_item;
  }

  @Override protected void initPresenter() {
    presenter = new AddBankPresenter(getActivity(), this, this);
    presenter.init();
  }

  @Override public void initView() {
    tvTitle.setText("选择银行卡");

    recycleView.setLayoutManager(new LinearLayoutManager(getActivity()));
    RecyclerViewDivider.with(mActivity).build().addTo(recycleView);

    mAdapter = new BankListAdapter();
    recycleView.setAdapter(mAdapter);

    presenter.loadBankList();

    mAdapter.setOnItemClickListener((position, object) -> {
      Intent intent = new Intent();
      intent.putExtra("banklist",object);
      setFragmentResult(RESULTCODE,intent);
      popBackStack();
    });
  }

  @Override public void loadBankListSuccess(List<BankList> list) {
    mAdapter.notifyList(list);
  }

  @OnClick(R.id.iv_back) public void onViewClicked() {
    popBackStack();
  }
}
